$(function(){

    _hmt.push(['_trackEvent','微信登录-pc','click','微信登录-pc-绑定页面展现']);

    var tabIndex = $('.login-type li'),
        tabContent = $('.login-content li');
    tabIndex.on('click',function(){
        if(!$(this).hasClass('cur')){
            tabIndex.filter('.cur').removeClass('cur');
            $(this).addClass('cur');
            var index = tabIndex.index($(this));
            tabContent.filter('.cur').removeClass('cur');
            tabContent.eq(index).addClass('cur');
        }
    });

    var isSending = false;
    
    //用户名邮箱绑定
    $('#email-form').on('submit',function(e){
        e.preventDefault();
        if(isSending){
            return;
        }
        var username = $.trim($('#email-username').val()),
            password = $.trim($('#email-password').val());
        if(username == ""){
            alert("请输入邮箱或用户名");
            return;
        }
        if(password == ""){
            alert("请输入密码");
            return;
        }
        isSending = true;
        $.post("", {
            username: username, 
            password: password,
            logintype: "normal",
            csrfmiddlewaretoken: $('body').data('csrf')
        }, function(data) {
            _hmt.push(['_trackEvent','微信登录-pc','click','微信登录-pc-绑定已有账号']);
            isSending = false;
            if(data.success){
                window.location.href = data.next;
            }else{  
                alert(data.msg);
            }
        }, 'json');
    });
    $('#email-form .login-btn').click(function(){
        $('#email-form').submit();
    });
});